package com.uls.web.controller.czj;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.uls.common.annotation.Log;
import com.uls.common.core.controller.BaseController;
import com.uls.common.core.domain.AjaxResult;
import com.uls.common.enums.BusinessType;
import com.uls.czj.domain.CzjRoom;
import com.uls.czj.service.ICzjRoomService;
import com.uls.common.utils.poi.ExcelUtil;
import com.uls.common.core.page.TableDataInfo;

/**
 * 房间管理Controller
 * 
 * @author czj
 * @date 2024-11-11
 */
@RestController
@RequestMapping("/czj/room")
public class CzjRoomController extends BaseController
{
    @Autowired
    private ICzjRoomService czjRoomService;

    /**
     * 查询房间管理列表
     */
    @PreAuthorize("@ss.hasPermi('czj:room:list')")
    @GetMapping("/list")
    public TableDataInfo list(CzjRoom czjRoom)
    {
        startPage();
        List<CzjRoom> list = czjRoomService.selectCzjRoomList(czjRoom);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('czj:room:list')")
    @GetMapping("/getfloorid/{getfloorid}")
    public TableDataInfo getfloorid(@PathVariable("getfloorid") int getfloorid)
    {
        CzjRoom czjRoom = new CzjRoom();
        czjRoom.setFloorid((long) getfloorid);
        startPage();
        List<CzjRoom> list = czjRoomService.selectCzjRoomList(czjRoom);
        if (list.size()==0){
            list.add(czjRoom);
        }
        return getDataTable(list);
    }

    /**
     * 导出房间管理列表
     */
    @PreAuthorize("@ss.hasPermi('czj:room:export')")
    @Log(title = "房间管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CzjRoom czjRoom)
    {
        List<CzjRoom> list = czjRoomService.selectCzjRoomList(czjRoom);
        ExcelUtil<CzjRoom> util = new ExcelUtil<CzjRoom>(CzjRoom.class);
        util.exportExcel(response, list, "房间管理数据");
    }

    /**
     * 获取房间管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('czj:room:query')")
    @GetMapping(value = "/{roomid}")
    public AjaxResult getInfo(@PathVariable("roomid") Long roomid)
    {
        return success(czjRoomService.selectCzjRoomByRoomid(roomid));
    }

    /**
     * 新增房间管理
     */
    @PreAuthorize("@ss.hasPermi('czj:room:add')")
    @Log(title = "房间管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CzjRoom czjRoom)
    {
        czjRoom.setRoomid(czjRoom.getFloorid()*100+ Long.parseLong(czjRoom.getRoomnumber()));
        return toAjax(czjRoomService.insertCzjRoom(czjRoom));
    }

    /**
     * 修改房间管理
     */
    @PreAuthorize("@ss.hasPermi('czj:room:edit')")
    @Log(title = "房间管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CzjRoom czjRoom)
    {
        return toAjax(czjRoomService.updateCzjRoom(czjRoom));
    }

    /**
     * 删除房间管理
     */
    @PreAuthorize("@ss.hasPermi('czj:room:remove')")
    @Log(title = "房间管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roomids}")
    public AjaxResult remove(@PathVariable Long[] roomids)
    {
        return toAjax(czjRoomService.deleteCzjRoomByRoomids(roomids));
    }
}
